package com.lagou.service.impl;

import com.lagou.service.HelloService;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.log4j.Logger;

import java.util.Random;

@Service
public class HelloServiceImpl implements HelloService {

    private Logger logger = Logger.getLogger(this.getClass());

    @Override
    public String sayHello(String name) {
        String ip = (String) RpcContext.getContext().getAttachment("client_ip");
        logger.info("client_ip: "+ip);
        return "hello: "+name+",  client_ip: "+ip;
    }

    @Override
    public String methodA() {
        try {
            Thread.sleep(new Random().nextInt(100));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        logger.info("methodA call");
        return "methodA";
    }

    @Override
    public String methodB() {
        try {
            Thread.sleep(new Random().nextInt(100));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        logger.info("methodB call");
        return "methodB";
    }

    @Override
    public String methodC() {
        try {
            Thread.sleep(new Random().nextInt(100));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        logger.info("methodC call");
        return "methodC";
    }
}
